<!--
  Copyright © 2016 Cask Data, Inc.

  Licensed under the Apache License, Version 2.0 (the "License"); you may not
  use this file except in compliance with the License. You may obtain a copy of
  the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  License for the specific language governing permissions and limitations under
  the License.
-->

<div class="union-schema-container">
  <div class="error"
       ng-if="UnionSchema.error">
    {{ UnionSchema.error }}
  </div>

  <fieldset ng-disabled="UnionSchema.isDisabled">
    <div class="item"
         ng-repeat="item in UnionSchema.types track by $index">
      <div class="clearfix">
        <div class="input-column select-only no-type"
             ng-class="{ 'tab-header': item.nested }">
          <div class="tab-header-inner">
            <div class="select-wrapper">
              <select class="form-control"
                      ng-model="item.displayType"
                      ng-options="option as option for option in UnionSchema.SCHEMA_TYPES"
                      ng-change="UnionSchema.changeType(item)">
              </select>
            </div>
          </div>
        </div>

        <div class="fields-actions">
          <div class="checkbox text-center">
            <input type="checkbox"
                   ng-model="item.nullable"
                   ng-change="UnionSchema.formatOutput()">
          </div>

          <div class="actions-buttons text-right" ng-if="!UnionSchema.isDisabled">
            <button class="btn btn-link"
                    ng-click="UnionSchema.removeType($index)"
                    ng-if="UnionSchema.types.length > 1">
              <i class="text-danger fa fa-trash"></i>
            </button>
            <button class="btn btn-link"
                    ng-click="UnionSchema.addType($index)">
              <i class="fa fa-plus"></i>
            </button>
          </div>
        </div>
      </div>

      <my-embedded-schema-selector
        type="item.type"
        display-type="item.displayType"
        parent-format-output="UnionSchema.formatOutput()"
        is-disabled="UnionSchema.isDisabled">
      </my-embedded-schema-selector>
    </div>
  </fieldset>
</div>
